from scapy.all import sniff, ls

class Sniffer:
    def __init__(self):
        self.__packet__ = []
    
    @property
    def packet(self):
        return self.__packet__[::]
    
    def sniff(self, amount, filter=''):
        result = sniff(count=amount, filter=filter)
        self.__packet__ += result.res
        return self.packet
    
    def search(self, protocol='TCP'):
        output = []
        protocol = protocol.upper()
        if protocol=='ETHER':
            protocol = 'Ether'
        for packet in self.packet:
            try:
                output.append(packet[protocol])
            except:
                pass
        return output
    
    def clear(self):
        self.__packet__ = []
